package com.aiyige.utils;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.aiyige.MyApp;

/**
 * Created by zhuyakun on 2017/9/27.
 */

public class PreferenceUtil {

    static SharedPreferences pref = null;

    private static void maybeInit() {
        if (pref == null) {
            pref = PreferenceManager.getDefaultSharedPreferences(MyApp.getAppContext());
        }
    }

    public static String getString(String key, String defaultValue) {
        maybeInit();
        return pref.getString(key, defaultValue);
    }

    public static void putString(String key, String value) {
        maybeInit();
        pref.edit().putString(key, value).commit();
    }

    public static boolean getBoolean(String key, boolean defaultValue) {
        maybeInit();
        return pref.getBoolean(key, defaultValue);
    }

    public static void putBoolean(String key, boolean value) {
        maybeInit();
        pref.edit().putBoolean(key, value).commit();
    }

    public static void putLong(String key, long value) {
        maybeInit();
        pref.edit().putLong(key, value).commit();
    }

    public static long getLong(String key,long defaultValue) {
        maybeInit();
        return pref.getLong(key, defaultValue);
    }

}
